package com.db.person.controller;

import com.db.person.util.VerifyCodeUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.OutputStream;

@Controller
public class CodeController {

    @RequestMapping("/checkCode")//使用io流的方式
    public void getCode(String num, HttpSession session, HttpServletResponse response, Model model) throws IOException {

        OutputStream outputStream=response.getOutputStream();
        int w = 200, h = 80;
        String code = VerifyCodeUtils.generateVerifyCode(4);
        session.setAttribute("code", code);//把之前生成好的验证码放到session中
        VerifyCodeUtils.outputImage(w, h, outputStream, code);
        outputStream.close();

    }


}
